package com.play.ballen.synthetic.ui

import android.content.Context
import android.content.Intent
import androidx.fragment.app.Fragment
import com.play.ballen.R
import com.play.ballen.databinding.ActivityRecordListBinding
import com.play.ballen.synthetic.ui.fragment.GuessListFragment
import com.play.ballen.synthetic.ui.fragment.SyntheticListFragment
import com.play.ballen.synthetic.ui.fragment.WinListFragment
import com.yuven.appframework.adapter.BaseViewPagerAdapter
import com.yuven.appframework.base.BaseStdTitleActivity
import com.yuven.baselib.component.viewmodel.BaseViewModel.EmptyVM
import com.yuven.baselib.utils.ResourceUtil

class NewSyntheticRecordActivity : BaseStdTitleActivity<EmptyVM, ActivityRecordListBinding>() {

    private val fragmentList by lazy {
        arrayListOf<Fragment>(
            GuessListFragment.newInstance(TYPE_RECORD_BUY),
            SyntheticListFragment.newInstance(TYPE_RECORD_SALE),
            WinListFragment.newInstance(TYPE_RECORD_SALE)
        )
    }

    private lateinit var adapter: BaseViewPagerAdapter
    private val titles = arrayListOf(
        ResourceUtil.getString(R.string.jingcai_jilu),
        ResourceUtil.getString(R.string.synthetic_record_title),
        ResourceUtil.getString(R.string.zhongqian),
    )

    companion object {

        const val TYPE_RECORD_BUY = "0"
        const val TYPE_RECORD_SALE = "1"

        @JvmStatic
        fun start(context: Context, index: Int) {
            val starter = Intent(context, NewSyntheticRecordActivity::class.java)
            starter.putExtra("index", index) // 传入索引值
            context.startActivity(starter)
        }
    }

    override fun viewModelClass(): Class<EmptyVM> {
        return EmptyVM::class.java
    }

    override fun contentLayoutId(): Int {
        return R.layout.activity_record_list
    }

    override fun initData() {
        adapter = BaseViewPagerAdapter(supportFragmentManager, fragmentList, titles)
        dataBinding.viewPager.adapter = adapter
        dataBinding.viewPager.offscreenPageLimit = fragmentList.size
        dataBinding.tabLayout.setViewPager(dataBinding.viewPager)
        // 根据外部传入的索引值切换到相应的 Fragment
        val externalIndex = intent?.getIntExtra("index", 0) ?: 0
        dataBinding.viewPager.currentItem = externalIndex

    }

    override fun initIntent(intent: Intent?) {
    }

    override fun getToolBarTitle(): String = ResourceUtil.getString(R.string.mall_record_title)
}